package com.tianqingwl.gsystem.tags;

import com.tianqingwl.gsystem.common.enumeration.SysConfigConstants;
import org.thymeleaf.context.IExpressionContext;
import org.thymeleaf.expression.IExpressionObjectFactory;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

public class GSystemExpressionObjectFactory implements IExpressionObjectFactory {
    public static final String SYSTEM_CONFIG_CONST_EXPRESSION_OBJECT_NAME="sysConfigConst";
    protected static final Set<String> ALL_EXPRESSION_OBJECT_NAMES =
            Collections.unmodifiableSet(new LinkedHashSet<String>(java.util.Arrays.asList(
                    new String[]{
                            SYSTEM_CONFIG_CONST_EXPRESSION_OBJECT_NAME,
                    }
            )));
    private static final SysConfigConstants SYSCONFIGCONSTANTS = new SysConfigConstants() {};

    @Override
    public Set<String> getAllExpressionObjectNames() {
        return ALL_EXPRESSION_OBJECT_NAMES;
    }

    @Override
    public Object buildObject(IExpressionContext context, String expressionObjectName) {
        if (SYSTEM_CONFIG_CONST_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)){
            return SYSCONFIGCONSTANTS;
        }
        return null;
    }

    @Override
    public boolean isCacheable(String expressionObjectName) {
        return true;
    }
}
